/*
 * @lc app=leetcode id=149 lang=cpp
 *
 * [149] Max Points on a Line
 */
class Solution {
public:
    int maxPoints(vector<vector<int>>& points) {
        unordered_map<int, vector<int>> memo;
        int len = points.size();


        int idx = 0;
        bool online = false;
        for (int i=0; i<len; i++) {
            online = false;
            for (auto it : memo) {
                idx = it.first;
                if (points[i][0]*points[idx][1] == points[i][1]*points[idx][0]) {
                    memo[idx].push_back(i);
                    online = true;
                }
            }
            if (!online) {
                memo[i] = {i};
            }
        }
        int max = 1;
        for (auto it : memo) {
            if (it.second.size() > max) {
                max = it.second.size();
            }
        }
        return max;
    }
};

